package org.sdfc.model.dfc.collection

import com.documentum.fc.common.IDfId
import com.documentum.fc.common.IDfTime

import org.sdfc.model.attr._
import org.sdfc.model.dfc.DfcTypedObject

/** A single row of results from a collection.
 *  <p>
 *  Following constraints of collection traversal, a CollectionRow is invalidated
 *  once the collection moves to the next row.<br/>
 *  Subsequent uses are sanctioned with IllegalStateException.
 */
class CollectionRow (
  /** Underlying RichCollection, defined as var in order to allow invalidate(). */
  private var coll : RichCollection
)
extends DfcTypedObject {
  
  /** Returns the underlying RichCollection or throws if this has been invalidated.  */
  protected def underlying : RichCollection =
    if ( coll != null ) coll
    else throw new IllegalStateException("CollectionRow: invalidated") 
  
  
  /** Invalidates this for all use.<br/>
   *  This method is called when the collection moves to the next row.
   */
  protected[collection] def invalidate() { coll = null }
  
  
  /** Reads the value of a SingleBooleanAttribute. */
  def getBoolean(attr : SingleBooleanAttribute) : Boolean = underlying.getBoolean(attr)
  
  /** Reads the value of a SingleIntAttribute. */
  def getInt(attr : SingleIntAttribute) : Int = underlying.getInt(attr)
  
  /** Reads the value of a SingleStringAttribute. */
  def getString(attr : SingleStringAttribute) : String = underlying.getString(attr)
  
  /** Reads the value of a SingleIdAttribute. */
  def getId(attr : SingleIdAttribute) : IDfId = underlying.getId(attr)
  
  /** Reads the value of a SingleTimeAttribute. */
  def getTime(attr : SingleTimeAttribute) : IDfTime = underlying.getTime(attr)
  
  /** Reads the value of a SingleDoubleAttribute. */
  def getDouble(attr : SingleDoubleAttribute) : Double = underlying.getDouble(attr)
  
  
  /** Counts the values of a RepeatingAttribute. */
  def getValueCount(attr : RepeatingAttribute[_]) : Int = underlying.getValueCount(attr)
  
  /** Reads the value of a RepeatingBooleanAttribute at a given index. */
  def getRepeatingBoolean(attr : RepeatingBooleanAttribute, index : Int) : Boolean = underlying.getRepeatingBoolean(attr, index)
  
  /** Reads the value of a RepeatingIntAttribute at a given index. */
  def getRepeatingInt(attr : RepeatingIntAttribute, index : Int) : Int = underlying.getRepeatingInt(attr, index)
  
  /** Reads the value of a RepeatingStringAttribute at a given index. */
  def getRepeatingString(attr : RepeatingStringAttribute, index : Int) : String = underlying.getRepeatingString(attr, index)
  
  /** Reads the value of a RepeatingIdAttribute at a given index. */
  def getRepeatingId(attr : RepeatingIdAttribute, index : Int) : IDfId = underlying.getRepeatingId(attr, index)
  
  /** Reads the value of a RepeatingTimeAttribute at a given index. */
  def getRepeatingTime(attr : RepeatingTimeAttribute, index : Int) : IDfTime = underlying.getRepeatingTime(attr, index)
  
  /** Reads the value of a RepeatingDoubleAttribute at a given index. */
  def getRepeatingDouble(attr : RepeatingDoubleAttribute, index : Int) : Double = underlying.getRepeatingDouble(attr, index)
  
  
  /** Searchs the values of a RepeatingBooleanAttribute for a given one and returns its index, -1 for not found. */
  def findBoolean(attr : RepeatingBooleanAttribute, value : Boolean) : Int = underlying.findBoolean(attr, value)
  
  /** Searchs the values of a RepeatingIntAttribute for a given one and returns its index, -1 for not found. */
  def findInt(attr : RepeatingIntAttribute, value : Int) : Int = underlying.findInt(attr, value)
  
  /** Searchs the values of a RepeatingStringAttribute for a given one and returns its index, -1 for not found. */
  def findString(attr : RepeatingStringAttribute, value : String) : Int = underlying.findString(attr, value)
  
  /** Searchs the values of a RepeatingIdAttribute for a given one and returns its index, -1 for not found. */
  def findId(attr : RepeatingIdAttribute, value : IDfId) : Int = underlying.findId(attr, value)
  
  /** Searchs the values of a RepeatingTimeAttribute for a given one and returns its index, -1 for not found. */
  def findTime(attr : RepeatingTimeAttribute, value : IDfTime) : Int = underlying.findTime(attr, value)
  
  /** Searchs the values of a RepeatingDoubleAttribute for a given one and returns its index, -1 for not found. */
  def findDouble(attr : RepeatingDoubleAttribute, value : Double) : Int = underlying.findDouble(attr, value)
  
}
